package com.cheng.example.atguigu.view2.client39;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 阻塞队列api之抛出异常组
 * put放的意思
 * take拿的意思
 */
public class BlockingQueueDemo {
    static BlockingQueue<String> blockingQueue = new ArrayBlockingQueue(3);
    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            try {
                Thread.sleep(1000);
                System.out.println("放入d");
                blockingQueue.put("d");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        f3();
    }

    /**
     * 阻塞队列api之阻塞
     */
    public static void f3() throws InterruptedException {

        blockingQueue.put("a");
        blockingQueue.put("b");
        blockingQueue.put("c");
//        blockingQueue.put("d");
        System.out.println(blockingQueue.offer("d", 2, TimeUnit.SECONDS));

        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.peek());
    }


}
